<template>
  <div class="stock-selection">
    <a-card title="股票表现查询" class="selection-card">
      <a-form layout="inline" @submit.prevent="onSearchCode">
        <a-form-item label="股票代码">
          <a-input v-model:value="searchCode" placeholder="请输入股票代码" style="width: 220px" @pressEnter="onSearchCode" />
        </a-form-item>
        <a-form-item>
          <a-button type="primary" @click="onSearchCode">查询</a-button>
        </a-form-item>
      </a-form>
     
    </a-card>
    <a-card v-if="historyList.length" title="选股历史" class="history-card">
      <a-list :data-source="historyList" bordered>
        <template #renderItem="{ item }">
          <a-list-item>
            <span>{{ item.code }} - {{ item.past }}</span>
          </a-list-item>
        </template>
      </a-list>
    </a-card>
    <!-- 弹窗显示详细信息 -->
    <a-modal v-model:visible="modalVisible" :title="modalTitle" @ok="handleModalOk" :footer="null">
      <div style="white-space: pre-line; font-size: 1rem; color: #333;">
        {{ modalContent }}
      </div>
      <div style="text-align:right; margin-top:16px;">
        <a-button type="primary" @click="handleModalOk">关闭</a-button>
      </div>
    </a-modal>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'

const searchCode = ref('')
const showResult = ref(false)
const past = ref('')
const future = ref('')
const historyList = ref([])

// 新增弹窗相关
const modalVisible = ref(false)
const modalTitle = ref('')
const modalContent = ref('')

// const isInHistory = computed(() => {
//   return historyList.value.some(item => item.code === searchCode.value.trim())
// })

function onSearchCode() {
  const code = searchCode.value.trim()
  if (!code) {
    message.warning('请输入股票代码')
    showResult.value = false
    return
  }
  if (code === '600519') {
    past.value = '贵州茅台近三年业绩持续增长，股价稳步上升，分红率高，行业龙头地位稳固。'
    future.value = '预计未来仍具备较强成长性，受益于消费升级和品牌溢价，建议长期关注。'
    modalTitle.value = '贵州茅台（600519）详细分析'
    modalContent.value = '【公司简介】贵州茅台是中国白酒行业龙头，品牌影响力极强。\n【财务表现】近三年营收和净利润持续增长，毛利率高，现金流充沛。\n【行业地位】高端白酒市场占有率领先，具备较强护城河。\n【投资建议】适合长期持有，防御属性强，分红稳定。'
  } else if (code === '000001') {
    past.value = '平安银行业绩稳健，资产质量良好，近年股价波动较小。'
    future.value = '未来有望受益于金融科技转型，业绩有望持续改善。'
    modalTitle.value = '平安银行（000001）详细分析'
    modalContent.value = '【公司简介】平安银行是中国领先的股份制商业银行。\n【财务表现】资产质量优良，净息差稳定，风控能力强。\n【行业地位】金融科技转型领先，零售业务增长快。\n【投资建议】适合稳健型投资者，关注长期成长。'
  } else if (code === '300750') {
    past.value = '宁德时代作为动力电池龙头，营收和净利高速增长，市占率持续提升。'
    future.value = '新能源车渗透率提升将带动公司持续扩张，长期成长空间大。'
    modalTitle.value = '宁德时代（300750）详细分析'
    modalContent.value = '【公司简介】宁德时代是全球领先的动力电池制造商。\n【财务表现】营收和净利润高速增长，研发投入大。\n【行业地位】动力电池市占率全球第一，客户资源丰富。\n【投资建议】新能源车发展红利显著，成长性突出。'
  } else {
    past.value = '暂无该股票的详细历史表现数据。'
    future.value = '暂无该股票的未来趋势分析。'
    modalTitle.value = '暂无详细信息'
    modalContent.value = '未查询到该股票的详细分析数据。'
  }
  showResult.value = true
  modalVisible.value = true
}

function handleModalOk() {
  modalVisible.value = false
}

</script>

<style scoped>
/* 美化后的样式，修复嵌套和标签问题 */
.stock-selection {
  max-width: 540px;
  margin: 60px auto;
}
.selection-card {
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(24,144,255,0.08);
  margin-bottom: 28px;
  padding-bottom: 8px;
}
.search-form {
  margin-bottom: 8px;
}
.analysis-box {
  display: flex;
  align-items: flex-start;
  margin-top: 28px;
  background: linear-gradient(90deg,#f7faff 60%,#e6f7ff 100%);
  border-radius: 14px;
  padding: 22px 32px 18px 24px;
  border-left: 5px solid #1890ff;
  box-shadow: 0 2px 12px rgba(24,144,255,0.06);
}
.analysis-content {
  flex: 1;
}
.analysis-title {
  font-weight: 600;
  color: #1890ff;
  font-size: 1.08rem;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.analysis-detail {
  color: #333;
  font-size: 1rem;
  line-height: 1.8;
  margin-bottom: 2px;
}
.history-card {
  margin-top: 28px;
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(24,144,255,0.06);
}
.history-code {
  font-weight: bold;
  color: #1890ff;
  margin-right: 12px;
}
.history-past {
  color: #555;
}
@media (max-width: 600px) {
  .stock-selection {
    max-width: 98vw;
    margin: 16px auto;
  }
  .selection-card {
    padding: 0 2px 8px 2px;
  }
  .analysis-box {
    flex-direction: column;
    padding: 14px 8px 10px 8px;
  }
}
</style>